'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 1_study_memory_entity.py
* @Time: 2025/7/25
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain.chains.conversation.base import ConversationChain
from langchain.memory import ConversationEntityMemory
from langchain.memory.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
from langchain_openai import ChatOpenAI

dotenv.load_dotenv()
# 1、构建提示
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
chain = ConversationChain(
    llm = llm,
    prompt=ENTITY_MEMORY_CONVERSATION_TEMPLATE,
    memory=ConversationEntityMemory(llm=llm),
)
print(chain.invoke({"input":"你好我叫博小睿， 我最近在学习langchain"}))
print(chain.invoke({"input":"我最喜欢的编程语言是Python"}))
print(chain.invoke({"input":"我住在长沙"}))
res = chain.memory.entity_store.store
print(res)

